package com.example.environment.tools;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import org.springframework.stereotype.Component;

import java.net.SocketOption;
import java.security.*;
@Component
public class RsaUtils {


    private static KeyPair keyPair;



    @PostConstruct
    public  void init() {
        try {
            // 生成 RSA 密钥对
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(2048); // 设置密钥长度
            keyPair = keyPairGenerator.generateKeyPair();
            System.out.println("privateKey"+keyPair.getPrivate());
            System.out.println("publicKey"+keyPair.getPublic());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    public static KeyPair getKeyPair() {
        return keyPair;
    }

}
